const mongoose = require('mongoose');
const {Schema, model} = mongoose;

const apySchema = new Schema({
        time:   { type: Number },//,unique: true },
        //'Time [s]': {type: Number},
        /**format: { type: String },
        area:   { 
            name: {type: String},
            id:   {type: String},
            alpha3code: {type: String},
            alpha2code: {type: String},
        },*/
        /**name:   { type: String },
        area:   { type: String },
        format: { type: String },
        type:   { type: String },
        category: { type: String },
        gender: { type: String },
        divisionLevel: { type: Number },*/
    },{
        toJSON: {
            transform: function(doc, ret, options) {
                delete ret._id;
                delete ret.__v;
                return ret;
            }
        }
    });

apySchema.static('findById', function(id) { return this.findOne({wyId:id}); });
apySchema.static('removeById', function(id) { return this.remove({id}); });
apySchema.static('upsert', function(id, apyData) {
    return this.findOneAndUpdate({id}, apyData, { new:true, upsert: true })
});

module.exports = model('awayphys', apySchema);